public class Calculator{

    private Converter result(int syst, Integer str){
        switch (syst) {
            case 2: return new Bin(str);
            case 8: return new Oct(str);
            case 10: return new Dec(str);
            case 16: return new Hex(str);
            default:
                throw new RuntimeException("Unknown system");
        }
    }
    
    public Converter summ(Converter num1, Converter num2) {
        return result(num1.getSystem(), num1.get() + num2.get());
    }
    
    public Converter substr(Converter num1, Converter num2) {
        return result(num1.getSystem(), num1.get() - num2.get());
    }
    
    public Converter multi(Converter num1, Converter num2) {
        return result(num1.getSystem(), num1.get() * num2.get());
    }

    public Converter div(Converter num1, Converter num2) {
        if (num2.get() != 0){
            return result(num1.getSystem(), num1.get() / num2.get());
        }
        throw new RuntimeException("Division by zero");
    }
}

